package ar.com.solidussource.howmuchmobile.maps.overlays;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.*;
import ar.com.solidussource.howmuchmobile.R;
import ar.com.solidussource.howmuchmobile.activities.MarketClusterListActivity;
import ar.com.solidussource.howmuchmobile.activities.MarketDetailOnMapActivity;
import ar.com.solidussource.howmuchmobile.common.entities.Market;
import ar.com.solidussource.howmuchmobile.common.entities.Productprice;
import ar.com.solidussource.howmuchmobile.common.exception.ServiceException;
import ar.com.solidussource.howmuchmobile.maps.items.MarketItem;
import ar.com.solidussource.howmuchmobile.services.mocks.ProductPriceMockService;
import com.google.android.maps.ItemizedOverlay;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 12/11/12
 * Time: 14:38
 * To change this template use File | Settings | File Templates.
 */
public class MarketItemizedOverlay extends ItemizedOverlay<MarketItem> {

    private List<MarketItem> mOverlays = new ArrayList<MarketItem>();
    private Activity mContext;

    public MarketItemizedOverlay(Drawable drawable) {
        super(boundCenterBottom(drawable));
    }

    public MarketItemizedOverlay(Drawable defaultMarker, Activity context) {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
        populate();
    }

    @Override
    protected MarketItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    public synchronized void addOverlay(MarketItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected boolean onTap(int index) {
        MarketItem item = mOverlays.get(index);

        Intent intent = new Intent(mContext, MarketDetailOnMapActivity.class);
        intent.putExtra("market", item.getMarket());
        mContext.startActivity(intent);

        return true;
    }

}